import 'package:flutter/material.dart';
import 'package:wanchong/utils/common.dart';
import 'package:wanchong/widget/app_bar.dart';
import 'package:package_info/package_info.dart';

class About extends StatefulWidget {
  @override
  _AboutState createState() => _AboutState();
}

class _AboutState extends State<About> {
  String _version = "";
  var alertStyleB = TextStyle(fontSize: 18.0, color: Color(0xFF3C4450));
  var alertStyleA = TextStyle(fontSize: 18.0, color: Color(0xFF647280));
  @override
  void initState() {
    super.initState();
    PackageInfo.fromPlatform().then((PackageInfo packageInfo) {
      setState(() {
        _version = packageInfo.version;
      });
    });
  }

  TextStyle _bottomTextStyle =
      TextStyle(fontSize: 11.0, color: Color(0xFFB4BEC6));
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: MyAppBar(
        child: Stack(
          children: <Widget>[
            Center(
              child: Text(
                "关于萌宠管家",
                style: TextStyle(
                    color: Color(0xFF3C4450),
                    fontWeight: FontWeight.w700,
                    fontSize: 18.0),
              ),
            ),
            GestureDetector(
              onTap: () {
                // print("object");
                Navigator.of(context).pop();
              },
              child: Container(
                padding: EdgeInsets.only(right: 15.0),
                color: Colors.transparent,
                height: double.infinity,
                child: Image.asset("assets/login/top_return_icon.png"),
              ),
            )
          ],
        ),
      ),
      body: Container(
        height: double.infinity,
        child: Column(
          children: <Widget>[
            Expanded(
              child: ListView(
                physics: BouncingScrollPhysics(),
                children: <Widget>[
                  Container(
                    height: 228.0,
                    child: Column(
                      mainAxisAlignment: MainAxisAlignment.center,
                      children: <Widget>[
                        Container(
                          width: 80.0,
                          height: 80.0,
                          child: Image.asset(
                              "assets/setting/set_about_me_logo_img.png"),
                        ),
                        Text(
                          "Mcgj " + (_version == "" ? "" : "v" + _version),
                          style: TextStyle(
                              color: Color(0xFFFFCC33), fontSize: 12.0),
                        ),
                      ],
                    ),
                  ),
                  _customItem("合作洽谈", () {}),
                  _customItem("申诉举报", () {}),
                  _customItem("客服电话", () {
                    _phone();
                  }),
                ],
              ),
            ),
            Center(
              child: Text(
                "成都智汇萌宠信息科技有限责任公司",
                style: _bottomTextStyle,
              ),
            ),
            Center(
              child: Text(
                "@2019 Chengdu Sankuai Online Technology Co.,Lt",
                style: _bottomTextStyle,
              ),
            ),
            SizedBox(
              height: 50.0,
            ),
          ],
        ),
      ),
    );
  }

  Widget _customItem(title, callback) {
    return Container(
      color: Colors.white,
      padding: EdgeInsets.only(left: 15.0),
      child: Column(
        children: <Widget>[
          GestureDetector(
            onTap: () {
              callback();
            },
            child: Container(
              color: Colors.transparent,
              padding: EdgeInsets.only(right: 15.0, top: 24.0, bottom: 24.0),
              child: Row(
                mainAxisAlignment: MainAxisAlignment.spaceBetween,
                children: <Widget>[
                  Text(
                    title,
                    style: TextStyle(color: Color(0xFF3C4450), fontSize: 14.0),
                  ),
                  Icon(
                    Icons.chevron_right,
                    color: Color(0xFFB4BEC6),
                    size: 20.0,
                  )
                ],
              ),
            ),
          ),
          Divider(
            color: Color(0xFFDBDBDB),
            height: 1.0,
          )
        ],
      ),
    );
  }

  void _phone() {
    showDialog<Null>(
        context: context,
        builder: (BuildContext context) {
          return AlertDialog(
            contentPadding: EdgeInsets.all(0.0),
            content: Container(
              color: Colors.white,
              width: 320.0,
              height: 250.0,
              child: Column(
                children: <Widget>[
                  Container(
                    // color: Colors.red,
                    padding: EdgeInsets.fromLTRB(70.0, 24.0, 70.0, 24.0),
                    child: Column(
                      children: <Widget>[
                        Center(
                          child: Text("客服热线服务时间"),
                        ),
                        Center(
                          child: Text(
                            "09:00 ~ 21:00 * 365",
                            style: alertStyleB,
                          ),
                        ),
                      ],
                    ),
                  ),
                  Divider(
                    height: 1,
                    color: Color(0xFFDBDBDB),
                  ),
                  GestureDetector(
                    onTap: (){
                      launchPhone(phone: "4006 - 321 - 666");
                    },
                    child: Padding(
                      padding: EdgeInsets.only(
                        top: 15.0,
                        bottom: 15.0,
                      ),
                      child: Text(
                        "4006 - 321 - 666",
                        style: alertStyleA,
                      ),
                    ),
                  ),
                  Divider(
                    height: 1,
                    color: Color(0xFFDBDBDB),
                  ),
                  GestureDetector(
                    onTap: (){
                      launchPhone(phone: "4006 - 321 - 666");
                    },
                    child: Padding(
                      padding: EdgeInsets.only(
                        top: 15.0,
                        bottom: 15.0,
                      ),
                      child: Text(
                        "4006 - 321 - 666",
                        style: alertStyleA,
                      ),
                    ),
                  ),
                  Divider(
                    height: 1,
                    color: Color(0xFFDBDBDB),
                  ),
                  GestureDetector(
                      onTap: () {
                        Navigator.of(context).pop();
                      },
                      child: Container(
                        color: Colors.transparent,
                        child: Center(
                          child: Text(
                            "取消",
                            style: alertStyleB,
                          ),
                        ),
                        padding: EdgeInsets.only(top: 15.0),
                        width: double.infinity,
                      )),
                ],
              ),
            ),
          );
        });
  }
}
